<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
	<head>
		<%@ include file="/view/common/header.jsp"%> 
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>户型管理</title>
				<script src="../js/ajaxfileupload.js"></script>
		<script type="text/javascript">
			//查询
			function search(){
				$('#dg').datagrid('load',{
					    title:   $("#title").val() ,
				});
			}
			function imageFormate(value){
				return "<img style='height: 50px;width: 50px;' src='"+ value+ "'/>" ;
			}
			
			function uploadImage(id , preview){
	            $.ajaxFileUpload({
	                url: root+ '/file/uploadAnyFile.do',
	                type: 'post',
	                secureuri: false,             //一般设置为false
	                fileElementId: id,    // 上传文件的id、name属性名
	                dataType: 'json',             //返回值类型，一般设置为json、application/json
	                success: function(res, status){
	                    console.log(res);
	                    if(res.code == "0000"){
							console.log(res.data);
							   console.log(preview);
	                          $("#"+preview).attr("src",res.data);
							  $("#"+id+"_value").val(res.data);
	                     }else{
	                          alert(res.msg) ;
	                    }
	                },
	                error: function(data, status, e){

	                }
	            });
	        }



			//根据ID 删除数据
			function deleteById(url){

				var selectedRows=$("#dg").datagrid('getSelections');
				if(selectedRows.length!=1){
					$.messager.alert("系统提示","请选择一条要删除的的数据！");
					return;
				}
				var row=selectedRows[0];
				$.ajax({
					url:url,
					data:{houseModelId: row.houseModelId},
					success:function(e){
						$.messager.alert("系统提示","删除成功","info",function(){
							$('#dg').datagrid('reload');
						});
					},error:function(e){
						alert(e.message);
					}
				});
			}
		</script>
	</head>
<body style="margin:1px;">
	<!-- 工具栏  -->
	<div id="tb">
		<div>
			<a href="javascript:openAddDialog('添加户型 ' ,'../housemodel/save.do')" class="easyui-linkbutton" iconCls="icon-add" plain="true">新增</a>
			<a href="javascript:openModifyDialog('编辑户型 ' ,'../housemodel/save.do')" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
			<a href="javascript:deleteById('../housemodel/delete.do')" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
		</div>
		<div>
							&nbsp;户型名：&nbsp;<input type="text" id="title" size="20"  class="easyui-textbox" />&nbsp;
						
			<a href="javascript:search()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
		</div>
	</div>
	
	<!-- 查询表单 --> 
	<table id="dg" title="户型管理" class="easyui-datagrid"  pagination="true" rownumbers="true"  fit="true"  url="../housemodel/queryForPage.do"  toolbar="#tb">
		 <thead>
				<tr>
							<th data-options="field:'title',width:100" align="center">户型名</th>
							<th data-options="field:'picUrl',width:100,formatter:imageFormate" align="center">户型图</th>
							<th data-options="field:'description',width:100" align="center">详情描述</th>
							<th data-options="field:'houseType',width:100" align="center">户型</th>
							<th data-options="field:'houseArea',width:100" align="center">户型总面积</th>
							<th data-options="field:'actualArea',width:100" align="center">套内面积</th>
							<th data-options="field:'houseThumb',width:100" align="center">缩略图</th>
					
				</tr>
		</thead>
	</table>
	
	
	<!-- 弹出对话框 -->
	<div id="dlg" class="easyui-dialog" style="width: 700px;height:320px;padding: 10px 20px" closed="true" buttons="#dlg-buttons">
		<form id="fm" method="post" novalidate>
		
							<input id="houseModelId" name="houseModelId" type="hidden"  />
						 <div class="fitem">
			                <label>户型名:</label>
			                <input name="title" class="easyui-textbox easyui-validatebox"   data-options="required:true">   
	           			 </div>
	           			  <div class="fitem">
			                <label>户型图:</label>
			                  <input name="files" id="picUrl"  type="file"/>
							  <input id="picUrl_value" name="picUrl" type="hidden" />
			                  <input  type="button" value="上传文件" onclick="uploadImage('picUrl','picUrlPreview');" ></input>
	           			 </div>
	           			 
	           			 <div  class="fitem">
		                		<label>预览图片:</label>
								<img height="200" width="200" id="picUrlPreview" src=""/>
           				 </div>
	           			 
						 <div class="fitem">
			                <label>详情描述:</label>
			                <input name="description" class="easyui-textbox easyui-validatebox"    >   
	           			 </div>
						 <div class="fitem">
			                <label>户型总面积:</label>
			                <input name="houseArea" class="easyui-textbox easyui-validatebox"    >   
	           			 </div>
						 <div class="fitem">
			                <label>套内面积:</label>
			                <input name="actualArea" class="easyui-textbox easyui-validatebox"   >   
	           			 </div>
<!-- 						 <div class="fitem"> -->
<!-- 			                <label>缩略图:</label> -->
<!-- 			                <input name="houseThumb" class="easyui-textbox easyui-validatebox"    >    -->
<!-- 	           			 </div> -->
      </form>
	</div> 
	
	

	<!-- 保存和关闭按钮 -->
	<div id="dlg-buttons">
		<a href="javascript:save()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
		<a href="javascript:closeDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
	</div>
	
</body>
</html>